package com.shanghaionstar.home.util;

import android.content.Context;
import android.location.Location;

import com.onstar.cn.common.util.Constants;
import com.onstar.cn.common.util.EncryptUtil;
import com.onstar.cn.mag.publicService.response.PreferentialResEntity;
import com.shanghaionstar.utils.NavHolder;

/**
 * Created by OnStar on 2017/2/3.
 */

/**
 * 提供给车主生活二级页面生成所需entity
 */
public class PreferentialResFactory {

    public static final String CHEYIN_ATTRIBUTE_DATA = "idpUserID,vin,sodwRole,licensePlate,engineNumber,mobilePhoneNumber,emailAddress,firstName,lastName,make,model,latitude:LATITUDE ,longitude:LONGITUDE";

    public static final String VEHICLEINSPECTION_URL = "?source=onstar&business_type=vehicleInspection";

    //车检
    public static PreferentialResEntity createVehicleInspectionEntity(PreferentialResEntity entity, Context context) {
        if (entity == null) {
            entity = new PreferentialResEntity();
        }
        setCommEntityValue(entity, context);

//        entity.setUrl("http://59.46.215.194:8080/home/index?source=onstar&business_type=vehicleInspection");
        entity.setUrl(EncryptUtil.decryptBase64(context, Constants.PREFIX_CHE_YIN_URL) + Constants.VEHICLEINSPECTION_URL);
        return entity;
    }

    //保险
    public static PreferentialResEntity createAssuranceEntity(PreferentialResEntity entity, Context context) {
        if (entity == null) {
            entity = new PreferentialResEntity();
        }
        setCommEntityValue(entity, context);
        entity.setUrl(EncryptUtil.decryptBase64(context, Constants.ASSURANCE_URL));
        return entity;
    }

//    //违章
//    public static PreferentialResEntity createTrafficTicketEntity(PreferentialResEntity entity, Context context) {
//        if (entity == null) {
//            entity = new PreferentialResEntity();
//        }
//        setCommEntityValue(entity, context);
//        entity.setUrl("http://59.46.215.194:8080/home/index?source=onstar&business_type=trafficTicket&signature=4e09471e7fe8723fb9a3afa7cf94fb17286cdde2619846f0a0b243037cc150c2");
//        return entity;
//    }
//
//    //预约挂号
//    public static PreferentialResEntity createAppointmentRegistrationEntity(PreferentialResEntity entity, Context context) {
//        if (entity == null) {
//            entity = new PreferentialResEntity();
//        }
//        setCommEntityValue(entity, context);
//        entity.setUrl("http://59.46.215.194:8080/home/index?source=onstar&business_type=appointmentRegistration&signature=4e09471e7fe8723fb9a3afa7cf94fb17286cdde2619846f0a0b243037cc150c2");
//        return entity;
//    }

    private static void setCommEntityValue(PreferentialResEntity entity, Context context) {
        entity.setPartnerId("vcyber");
//        if (NavHolder.getInstance(context).getMyLocation() != null) {
        Location location = NavHolder.getInstance(context).getMyLocation();
        entity.setAttributeData(CHEYIN_ATTRIBUTE_DATA
                .replace("LATITUDE", location == null ? "" : String.valueOf(location.getLatitude()))
                .replace("LONGITUDE", location == null ? "" : String.valueOf(location.getLongitude())));
//        }
        entity.setHttpMethod("POST");
        entity.setContentType("JSON");
    }
}
